import axios from 'axios'
const baseURL = '/api'

const instance = axios.create({
  baseURL,
  timeout: 500,
  headers:{
    token:'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxNjk4MjkyODc5Mzc3NTQ1MDI0OmVuY3J5cHRQYXNzd29yZCIsImV4cCI6NDgzMDU0MTk1OH0.chZsFXmf6KN6H6h3k_mxw4F2WmxLNwAnz88FuWrGjdw'

  },
})

// 请求拦截器
instance.interceptors.request.use(function(config) {
    return config;
  }, function(error) {
    return Promise.reject(error);
  })
  
  // 响应拦截器
instance.interceptors.response.use(function(response) {
  return response;
}, function(error) {
  return Promise.reject(error);
})
 
export function request(url, params) {
    return new Promise((resolve, reject) => {
      instance.post(url, params)
        .then(response => {
          resolve(response.data);
        })
        .catch((error) => {
          reject(error);
        })
    })
  }

  export function requestGet(url, params) {
    return new Promise((resolve, reject) => {
      instance.get(url, params)
        .then(response => {
          resolve(response.data);
        })
        .catch((error) => {
          reject(error);
        })
    })
  }
   
  // export default {
  //   mockdata(url, params) {
  //     return fetch(url, params);
  //   }
  // }
 